//
//  SFStatus.swift
//  SFWeiBo
//
//  Created by 孙凡 on 16/4/11.
//  Copyright © 2016年 Edward. All rights reserved.
//

import UIKit

class SFStatus: NSObject {

    //文本
    var text: String?
    //创建时间
    var created_at: String?{
        didSet{

            creatTime = NSDate.creatTimeTextWith(created_at)
//            print(creatTime)
        }

    }
    //转换好的时间
    var creatTime: NSDate?


    //微博来源
    var source: String?
    //微博作者的用户信息字段
    var user: SFUser?
    //转发微博的信息
    var retweeted_status: SFStatus?
    //配图
    var pic_urls: [SFThumbnail]?


    //转发数
    var reposts_count: Int = 0
    //评论数
    var comments_count: Int = 0
    //点赞数
    var attitudes_count: Int = 0

    //微博id
    var id: Int64 = 0


    init(dict: [String: AnyObject] ) {
        super.init()

        setValuesForKeysWithDictionary(dict)
    }

    override func setValue(value: AnyObject?, forKey key: String) {

        if "user" == key {

            guard let v = value as? [String : AnyObject] else{

                return
            }

            user = SFUser(dict: v)

        } else if key == "retweeted_status"{

            guard let v = value as? [String: AnyObject] else{

                return
            }

            retweeted_status = SFStatus(dict: v)
//            print(v)

        } else if key == "pic_urls" {

            guard let v = value as? [[String: AnyObject]] else {

                return
            }

            var models:[SFThumbnail] = [SFThumbnail]()

            for dict in v {

                let model = SFThumbnail(dict: dict)

                models.append(model)
            }

            pic_urls = models

//            print(pic_urls)

        } else {

            super.setValue(value, forKey: key)
        }
    }

    override func setValue(value: AnyObject?, forUndefinedKey key: String) {    }


    override var description: String {

        let properties = ["text","created_at","source","user","reposts_count","comments_count","attitudes_count"]
//        let properties = ["reposts_count"]

        return String(dictionaryWithValuesForKeys(properties))
    }


}

//MARK: - 单张图片的类
class SFThumbnail: NSObject {

    var thumbnail_pic: String?

    init(dict: [String: AnyObject]) {

        super.init()
        setValuesForKeysWithDictionary(dict)
    }

    override func setValue(value: AnyObject?, forUndefinedKey key: String) {

    }

}

